// pages/register/register.js
const app = getApp()
const util = require('../../utils/util.js');
const util2 = require('../../utils/timeTool.js');
const CryptoJS = require('../../utils/aes-jia.js')
var timestamp = Date.parse(new Date()) / 1000; 
import Dialog from '../../dist/dialog/dialog';
var WxParse = require('../../wxParse/wxParse.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    istop:false,
    payment:1,
    dirty:[],
    isexamineorg:false,
    isexamineorg1: false,
    isexaminept: false,
    isexaminept1: false,
    ischeckAuth:true,
    ischeckAuth1: false,
    isexport:true,
    fileName:'',
    fileSize:'',
    leaveIntotalPages:1,
    pageNumber:1,
    pageNumber1: 1,
    isHeight:false,
    actStartTime:'',
    actEndTime:'',
    sharePicUrl:'',
    textH:'',
    textH1:'',
    tomore: '',
    isapplyEndTime:false,
    lists:[],
    hiddenName:true,
    hiddenName1: true,
    hiddenName2: true,
    isMsg:false,
    bgmsg:[],
    signIn:0,
    sex:"",
    nrheight:0,
    isOver:true,
    isShuax:true,
    isComment:true,
    groupNotice:'',
    changeMessageId:'',
    isLeaveOpen:false,
    paymentAmount:0,
    formId:'',
    replytex:'',
    parentId:'',
    inputname:'',
    focus: false,
    isFather: true,
    leaveInfo:[],
    leaveInfonum:'',
    hfindex:'',
    isBack:0,
    noticetext:'',
    ifNotice:false,
    wholeopen:false,
    showMore: app.globalData.showMore,
    bankCard: app.globalData.bankCard,
    concern: false,
    text: '关注"一起来往"公众号，及时享受活动提醒服务。',
    showSheet: false,
    registeEnd: false,
    registeOver: false,
    mine: false,
    myTransport: "",
    myTips: "",
    userInfo: {},
    dict: {},
    item: {},
    id: "",
    time: "",
    timeRecord: false,
    applyEnd: false,
    imgUrls: [],
    isCreate:false,
    show: false,
    isOpen: false,
    fullName:'',
    phoneNumber:'',
    addNumber:'',
    joinNumber:0,
    //已报名
    enrolment:false,
    participantList:[],
    participantListnum:'',
    participantListpages:'',
    //受邀人审核状态
    isCheck:'',
    extras:[],
    customInput:'',
    user:{},
    inputVal:[],
    customArray:[],
    isPopup:false,
    companyName:'',
    windowTitle:'',
    payWindow:false,
    idNumber:'',
    mailbox:'',
    address:'',
    partyBack:false,
    isShare: 0,
    showPayPwdInput: false,  //是否展示密码输入层
    pwdVal: '',  //输入的密码
    payFocus: true, //文本框焦点
    prepaymentRecordId: '',
    walletBalance:'',
    whetherSetPayPwd:'',
    actAccompanying:[],//随行人资料
    mediaObject:{
    source: "WechatApplet",
    activityID:"",
    type: "enroll"
    },
    source:'',
    isshare:false,//邀请页面
    isSucces:false,//报名成功
    _selData: {
      logoUrl: '',        //分享图
      headIcon: '',
      headIcon1:'',  //头像
      codeLogo: '',  //小程序码
    },

    island: false,
    islandshow: false,
    isPhone: false,
    loginShow:false
  },
  inputBindIdcard:function(e) {
    this.setData({
      idNumber: e.detail.value
    })
  },

  inputBindEmail: function (e) {
    console.log('邮箱', e.detail.value)
    this.setData({
      mailbox: e.detail.value.trim()
    })
  },

  inputBindAddress: function (e) {
    this.setData({
      address: e.detail.value.replace(/\s+/g, '')
    })
  },

  inputBindcompany: function (e) {
    this.setData ({
      companyName: e.detail.value.replace(/\s+/g, '')
    })
  },

  inputBindname: function (e) {
    this.setData({
      fullName: e.detail.value
    })
  },

  
  inputBindnumber: function (e) {
    console.log('随行人数', e.detail.value)
    this.setData({
      addNumber: e.detail.value,
      joinNumber: e.detail.value
    })
  },
  closeBtn(){
    this.setData({
      isshare:false,
    })
  },
  toleaveInfo(){
    if (this.data.istop){
      this.setData({
        istop: false,
      })
      wx.pageScrollTo({
        scrollTop: 0,
        duration: 300,
        success: function (res) {
          console.log('滚动成功')
        }
      })
    }else{
    this.setData({
      isComment: true,
      istop:true,
    })
    wx.pageScrollTo({
      selector: "#messagebox",
      duration: 300,
      success: function (res) {
        console.log('滚动成功')
      }
    })
    }
  },
  // 收藏
  collection(){
    var that = this;
    if (!this.data.island) {
      this.landbtn()
      return
    }
    app.req({
      url: "wechat/activity/addCollections",
      method: "post",
      data: {
        collectionId: that.data.id,
        type:0,
      },
      success: function (res) {
        if(res.code==200){
          wx.showToast({
            title: '添加收藏成功',
          })
          that.loadData()
        }
      }
    })
  },
  cancelCollection(){
    var that = this;
    if (!this.data.island) {
      this.landbtn()
      return
    }
    app.req({
      url: "wechat/activity/removeCollections",
      method: "post",
      data: {
        collectionId: that.data.id,
        type: 0,
      },
      success: function (res) {
        if (res.code == 200) {
          wx.showToast({
            title: '取消收藏成功',
          })
          that.loadData()
        }
      }
    })
  },
//自定义
  inputBindcustom:function(e) {
    var nowIdx = e.currentTarget.dataset.index;//获取当前索引
    var val = e.detail.value.replace(/\s+/g, '');//获取输入的值
    var oldVal = this.data.inputVal;
    console.log("oldVal", oldVal)
    oldVal[nowIdx] = val;//修改对应索引值的内容
    this.setData({
      inputVal: oldVal
    })
 
  },
  // 修改内容介绍
  xgintroduction(){
    var that = this
    wx.navigateTo({
      url: '/pages/outline/outline?id='+that.data.id,
    })
  },
//评论图片
  fdimg(e){
    console.log('图片',e)
    var arr = e.currentTarget.dataset.arr
    var index = e.currentTarget.dataset.index
    wx.previewImage({
      current: arr[index],     //当前图片地址
      urls: arr,               //所有要预览的图片的地址集合 数组形式
      success: function (res) { },
      fail: function (res) { },
      complete: function (res) { },
    })
  },
  //图片点击预览
  previewImg: function (e) {
    // console.log(e.currentTarget.dataset.index);
    var index = e.currentTarget.dataset.index;
    var imgArr = this.data.item.posterUrl;
    // console.log('图片地址', this.data.act2.posterUrl)
    // console.log(imgArr);
    wx.previewImage({
      current: imgArr[index],     //当前图片地址
      urls: imgArr,               //所有要预览的图片的地址集合 数组形式
      success: function (res) { },
      fail: function (res) { },
      complete: function (res) { },
    })
  },
  wxlogin: function () {//获取用户的openID和sessionKey
    var that = this;
    wx.login({
      //获取code 使用wx.login得到的登陆凭证，用于换取openid
      success: (res) => {
        wx.request({
          method: "GET",
          url: 'https://xxxwx/wxlogin.do',
          data: {
            code: res.code,
            appId: "appIdSbcx",
            appKey: "appKeySbcx"
          },
          header: {
            'content-type': 'application/json' // 默认值
          },
          success: (res) => {
            console.log(res);
            that.setData({
              sessionKey: res.data.session_key
            });
          }
        });
      }
    });
  },

  phone: function () {
    wx.makePhoneCall({
      phoneNumber: this.data.item.telphone,
      success: function () {
        console.log("拨打电话成功！")
      },
      fail: function () {
        console.log("拨打电话失败！")
      }
    })

  },
//获取手机号
  fillButtonClick(e){
    console.log("获取手机号");
    console.log(e);
    var iv = e.detail.iv
    var encryptedData = e.detail.encryptedData
    var appid = 'wxa0535d31b27c14d8'
  },

  //自定义缴费金额
  sponsorMoney:function(e) {
    console.log('缴费', e.detail.value)
    e.detail.value = e.detail.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
    e.detail.value = e.detail.value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3');

    if (e.detail.value.indexOf(".") < 0 && e.detail.value != "") {
      e.detail.value = parseFloat(e.detail.value);
    } else if (e.detail.value.indexOf(".") == 0) {
      e.detail.value = e.detail.value.replace(/[^$#$]/g, "0.");
      e.detail.value = e.detail.value.replace(/\.{2,}/g, ".");
    }
    if (e.detail.value > 500000) {
      e.detail.value = 500000
    }
    this.setData({
      paymentAmount: e.detail.value
    })
  },

  //继续报名
  continueSignUp:function () {
  var that = this
   that.toggle("item.perCapita", "");
   that.toggle("outTradeNo", "");
   that.setData({
    paymentAmount:0,
    payWindow: false
   })
   that.goToRegisterPage();
  },

  //支付金额
  paymentMoney: function () {
    var that = this
    if (that.data.paymentAmount.length == 0) {
      wx.showToast({
        title: "请输入支付金额",
        icon: 'none',
        duration: 2000
      })
      return
    } 
    if (that.data.paymentAmount == 0) {
      wx.showToast({
        title: "支付金额不能为0",
        icon: 'none',
        duration: 2000
      })
      return
    }
    // if (that.data.paymentAmount <= 0.01) {
    //   wx.showToast({
    //     title: "支付金额需大于0.01元",
    //     icon: 'none',
    //     duration: 2000
    //   })
    //   return
    // }
    if (that.data.paymentAmount >= 0.01){
      that.setData({
        payWindow: false,
        show:true
      })
      // that.addToActivity()
      that.getWalletBalance();
    }
  },
  timeConflicts() {
  var that = this;
   app.req({
     url: "wechat/act/roster/timeConflict",
     method: "post",
     data: {
       activityId: that.data.id,
       actStartTime: that.data.item.actStartTime,
       actEndTime: that.data.item.actEndTime
     },
     success: function (res) {
       console.log("报名的时候", res)
      //  console.log("人数", that.data.item.perCapita, 1 + parseInt(that.data.joinNumber))
       if (that.data.item.chooseConsume==1){
         console.log(that.data.item.perCapita, parseInt(that.data.joinNumber))
        //  var paymentAmounts = that.data.item.perCapita
         var paymentAmounts = that.data.item.perCapita*(1 + parseInt(that.data.joinNumber))
          console.log('缴费1',paymentAmounts)
         that.setData({
           paymentAmount: paymentAmounts
         })
       } else if (that.data.item.chooseConsume == 5 || that.data.item.chooseConsume == 8){
        var paymentAmounts = that.data.item.perCapita;
         console.log('缴费1', paymentAmounts, that.data.item.perCapita)
         that.setData({
           paymentAmount: paymentAmounts
         })
       }
       
       if (res.code == 200) {
         console.log("进来了ooooo")
        //  if (that.data.item.chooseConsume == 1) {
        //    //需要支付金额
        //    that.toggle("show", true);
        //  } else {
        //    //有人请客
        //    that.toggle("item.perCapita", "");
        //    that.toggle("outTradeNo", "");
        //    that.goToRegisterPage();
        //  }
         if ((that.data.item.chooseConsume == 1 || that.data.item.chooseConsume == 5 || that.data.item.chooseConsume == 8) && ((that.data.isCreate && that.data.item.orgActType==2)||!that.data.isCreate)){
          //需要支付金额
          that.toggle("show", true);
           that.getWalletBalance();
        } else
        // else if (that.data.item.chooseConsume == 2 || that.data.item.chooseConsume == 3){
        //   //请客或者免费
        //   that.setData({
        //     windowTitle:"本活动您无需缴费",
        //     payWindow:true
        //   })
        // } else 
        if (that.data.item.chooseConsume == 7 && ((that.data.isCreate && that.data.item.orgActType == 2) || !that.data.isCreate)) {
          //自愿
          that.setData({
            windowTitle: "自愿缴费",
            payWindow: true
          })
        } 
        else {
          that.toggle("item.perCapita", "");
          that.toggle("outTradeNo", "");
          that.goToRegisterPage();
        }

       } else {
         Dialog.confirm({
           message: res.msg,
           confirmButtonText: "是",
           cancelButtonText: "否"
         }).then(() => {
          //  if (that.data.item.chooseConsume == 1) {
          //    //需要支付金额
          //    that.toggle("show", true);
          //  } else {
          //    //有人请客
          //    that.toggle("item.perCapita", "");
          //    that.toggle("outTradeNo", "");
          //    that.goToRegisterPage();
          //  }
           if ((that.data.item.chooseConsume == 1 || that.data.item.chooseConsume == 5 || that.data.item.chooseConsume == 8) && ((that.data.isCreate && that.data.item.orgActType == 2) || !that.data.isCreate)) {
             //需要支付金额
             that.toggle("show", true);
             that.getWalletBalance();
           } else
          //  else if (that.data.item.chooseConsume == 2 || that.data.item.chooseConsume == 3) {
          //    //请客或者免费
          //    that.setData({
          //      windowTitle: "本活动您无需缴费",
          //      payWindow: true
          //    })
          //  } else
           if (that.data.item.chooseConsume == 7 && ((that.data.isCreate && that.data.item.orgActType == 2) || !that.data.isCreate)) {
             //自愿
             that.setData({
               windowTitle: "自愿缴费",
               payWindow: true
             })
           } 
           else {
             that.toggle("item.perCapita", "");
             that.toggle("outTradeNo", "");
             that.goToRegisterPage();
           }
         }).catch(() => {
           // on cancel
         });
       }
     }
   })
 },


  goToRegisterPage: function () {
    console.log("点击报名了")
    var that = this;
    app.req({
      url: "wechat/act/participation/save",
      method: "post",
      data: {
        activityId: that.data.id,
        name: that.data.fullName,
        sex:that.data.sex,
        telphone: that.data.phoneNumber,
        company:that.data.companyName,
        idcard:that.data.idNumber,
        email:that.data.mailbox,
        address:that.data.address,
        enrollment: that.data.joinNumber,
        outTradeNo: that.data.outTradeNo,
        formId: that.data.formId,
        paymentAmount: that.data.paymentAmount,
        perCapita: that.data.item.perCapita,
        participationFields: that.data.customArray,
        actAccompanying: that.data.actAccompanying,
      },
      showLoad: true,
      success: function (res) {
        if (res.code == 200) {
          if(!that.data.user.realName) {
            var value = {
              realName: that.data.fullName
            }
            that.saveInfo(value)
          }
          if (!that.data.user.telphone) {
            var value = {
              telphone: that.data.phoneNumber
            }
            that.saveInfo(value)
          }
          that.setData({
            participantList: [],
            pageNumber: 1,
            show: false,
            isSucces:true,
            isOpen:false
          })

          // if(that.data.item.isCheck == 1) {
          //   wx.showToast({
          //     title: "报名已提交审核",
          //     duration: 2000
          //   })
          // } else {
          //   wx.showToast({
          //     title: "恭喜您报名成功",
          //     duration: 2000
          //   })
          // }
          // wx.switchTab({
          //   url: '/pages/index/index'
          // })
          that.loadData()
          that.listActParticipantByAct()
          that.participantList(1)
        } else {
          console.log("报名失败", res.msg)
          that.setData({
            show: false,
            isOpen: false,
          })
          wx.showToast({
            title: res.msg,
            icon: 'none',
            duration: 2000
          })
        }
      }
    });
  },

  shareaAtivity:function () {
    app.TestBuriedPoint('yqlw_invitation_invitation')
    wx.navigateTo({
      url: '/pages/partyInvitation/partyInvitation?id=' + this.data.id
    })
  },

  //写留言
  topLeaveMsg: function () {
    app.TestBuriedPoint('yqlw_invitation_message')
    this.setData({
      isFather: true,
      focus:true,
      replytex:'写留言：'
    })
  },
  //确认  
  confirmreply: function () {
    let that = this
    if (that.data.inputname == '') {
      wx.showToast({
        title: '内容不能为空',
        icon: 'none',
        duration: 2000
      })
    } else {
      if (that.data.inputname != '') {
        var n = 0
        // console.log('词库2', this.data.dirty.length)
        for (var i = 0; i < this.data.dirty.length; i++) {
          // console.log('循环')
          if (that.data.inputname.indexOf(this.data.dirty[i]) >= 0) {
            console.log('查询2')
            wx.showToast({
              title: '您输入的内容有违禁词，敏感词已被替换成星号,请编辑后重新提交',
              icon: 'none',
              duration: 2000
            })
            var fw = this.data.dirty[i]
            var fw1 = ''
            for (var k = 0; k < fw.length; k++) {
              fw1 = fw1 + '*'
            }
            var activityProcess = that.data.inputname.replace(fw, fw1)
            that.setData({
              inputname: activityProcess
            });
            console.log('替换', that.data.inputname)
            // console.log('替换1', activityProcess)
            n = n + 1
          }
        }
        if (n > 0) {
          return
        }
      }
      if (that.data.isFather) {
        console.log('true')
        var data = {
          "activityId": that.data.id,
          "content": that.data.inputname,
        }
      } else {
        console.log('false')
        var data = {
          "activityId": that.data.id,
          "content": that.data.inputname,
          "parentId": that.data.parentId
        }
      }
      app.req({
        url: "wechat/actcomments/save",
        method: "post",
        data: data,
        success: function (res) {
          wx.showToast({
            title: '留言成功',
            icon: 'none',
            duration: 2000
          })
          that.setData({
            inputname:''
          })
          if (that.data.isFather){
            that.setData({
              leaveInfo:[],
              pageNumber1:1,
            })
            that.getLeaveMessage()
          }else{
            var hfindex = that.data.hfindex
            var index = "leaveInfo[" + hfindex + "].list"
            var index1 = "leaveInfo[" + hfindex + "].flag"
            that.setData({
              [index]: that.data.leaveInfo[hfindex].list.concat(res.data),
              [index1]: true,
              participantListnum: that.data.participantListnum+1
            })
            console.log(that.data.leaveInfo)
          }
          
        }
      });
    }
    this.setData({
      focus: false
    })
  },
  //回复
  reply: function (e) {
    getApp().mtj.trackEvent('yqlw_act_reply');
    var nameid = e.currentTarget.dataset.name
    var hfindex = e.currentTarget.dataset.index
    console.log('回复：' + (hfindex),e)
    this.setData({
      parentId: e.currentTarget.dataset.id,
      isFather: false,
      focus: true,
      hfindex:hfindex,
      replytex: '回复' + nameid + ':'
    })
  },
  bindblur:function(){
    this.setData({
      focus: false
    })
  },
  //留言
  formName: function (e) {
    this.setData({
      inputname: e.detail.value.replace(/\s+/g, '')
    })
  },
  //删除
  deletereply: function (event) {
    var that = this;
    console.log(event.currentTarget.id)
    let id = event.currentTarget.id
    let data = {
      "id": event.currentTarget.id,
      "activityId": that.data.id,
    }
    wx.showModal({
      title: '提示',
      content: '您确定要删除当前评论吗?',
      confirmColor: '#2168EB',
      success(res) {
        if (res.confirm) {
          app.req({
            url: "wechat/actcomments/deleteComments",
            method: "post",
            data: data,
            success: function (res) {
              wx.showToast({
                title: res.msg,
                icon: 'success',
                duration: 2000
              })
              that.setData({
                leaveInfo: [],
                pageNumber1: 1,
              })
              that.getLeaveMessage()
            }
          });
        }
      }
    })
  },
  //分享列表
  getlists(){
    var that = this
    app.req({
      url: "wechat/act/participation/threeParticipantList",
      method: "post",
      data: {
        activityId: that.data.id
      },
      success: function (res) {
        console.log('分享列表',res)
        that.setData({
          lists:res.data
        })
      }
    });
  },
  //获取留言列表
  getLeaveMessage: function () {
    var that = this;
    app.req({
      url: "wechat/actcomments/list",
      method: "post",
      data:{
        activityId: that.data.id,
        pageNumber: that.data.pageNumber1,
        pageSize: 10
      },
      success: function (res) {
        if (200 == res.code) {
          that.setData({
            leaveInfo: that.data.leaveInfo.concat(res.data.rows),
            leaveInfonum:res.data.total,
            leaveIntotalPages: res.data.totalPages
          });
          console.log('留言',res.data)
        } else {
          wx.showToast({
            title: res.msg,
            icon: 'none',
            duration: 2000
          })
        }
      }
    });
  },
  //已报名名单
  participantList: function (a) {
    var that = this;
    app.req({
      url: "wechat/act/participation/participantList",
      method: "post",
      data: {
        activityId: that.data.id,
        type:1,
        pageNumber:that.data.pageNumber,
        pageSize:10,
      },
      success: function (res) {
        if (200 == res.code) {
          console.log('已报名', res)
          if (that.data.pageNumber==1){
            // console.log('微信支付', that.data.participantList, res)
            that.setData({
              participantList: res.data.rows,
              participantListnum: res.data.total,
              participantListpages: res.data.totalPages,
            })
            // console.log('微信支付', that.data.participantList)
          }else{
            that.setData({
              participantList: that.data.participantList.concat(res.data.rows),
              participantListnum: res.data.total,
              participantListpages: res.data.totalPages,
            })
            // console.log('微信支付', that.data.participantList)
          }
        } else {
          wx.showToast({
            title: res.msg,
            icon: 'none',
            duration: 2000
          })
        }
      }
    });
  },
  payment(e){
    var id = e.currentTarget.dataset.index
    this.toggle('payment',id)
  },
  //支付
  addToActivity1(e) {
    var that = this;
    var payWay = e.currentTarget.dataset.id;
    if (payWay == 0) {
      if (that.data.walletBalance < that.data.paymentAmount) {
        wx.showToast({
          title: "钱包余额不足",
          icon: 'none',
          duration: 2000
        })
        return
      } else {
        if (that.data.whetherSetPayPwd) {
          that.setData({
            showPayPwdInput: true,
            payFocus:true,
          })
        } else {
          wx.showModal({
            title: '温馨提示',
            content: '为了您的账号安全，请设置支付密码',
            showCancel:false,
            success(res) {
              if (res.confirm) {
                // 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
                wx.navigateTo({
                  url: '/pages/password/password',
                })
              }
            }
          })
        }
      }
    }
  },


  addToActivity: function (e) {
    var that = this;
    if(that.data.isOver){
      that.setData({
        isOver:false
      })
      var payWay = '';
      if (e == 0) {
        payWay = 0
      } else {
        payWay = e.currentTarget.dataset.id;
      }
    console.log("支付方式", payWay)
    var data = that.data;
    console.log("会费ssssss", that.data.paymentAmount, that.data.item.perCapita)
      wx.request({
        url: app.globalData.url +"wechat/wxpay/pay?uid=" + that.data.user.id + '&prepaymentRecordId=' + that.data.prepaymentRecordId,
      method: "post",
        header: {
          'api-client': '8693ece21a2711ea995200163e05ff66',
          'api-version': '1.3.1',
        },
      showLoad: true,
      data: {
        activityId: that.data.id,
        name: that.data.fullName,
        sex:that.data.sex,
        telphone: that.data.phoneNumber,
        company: that.data.companyName,
        idcard: that.data.idNumber,
        email: that.data.mailbox,
        address: that.data.address,
        enrollment: that.data.joinNumber,
        outTradeNo: that.data.outTradeNo,
        formId: that.data.formId,
        payWay: payWay,
        paymentAmount: that.data.paymentAmount,
        perCapita: that.data.item.perCapita,
        participationFields: that.data.customArray,
        actAccompanying: that.data.actAccompanying,
      },
      success: function (res) {
        console.log("支付", that.data.paymentAmount,res)
        if (res.data.code == 200 && payWay == 0){
          that.setData({
            participantList: [],
            pageNumber: 1,
            show: false,
            isOver:true,
            isSucces:true,
            isOpen:false
          })
          that.loadData()
          that.listActParticipantByAct()
          that.participantList(1)
          // if (that.data.item.isCheck == 1) {
          //   wx.showToast({
          //     title: "报名已提交审核",
          //     duration: 2000
          //   })
          // } else {
          //   wx.showToast({
          //     title: "恭喜您报名成功",
          //     duration: 2000
          //   })
          // }
        }else if (res.data.code == 200 && payWay==1) {
          var paydata = res.data.data;
          console.log("调取", paydata)
          wx.requestPayment({
            timeStamp: paydata.prepayDate.timeStamp,
            nonceStr: paydata.prepayDate.nonceStr,
            package: 'prepay_id=' + paydata.prepayDate.prepay_id,
            signType: 'MD5',
            paySign: paydata.prepayDate.paySign,
            success(res) {
              that.setData({
                outTradeNo: paydata.outTradeNo,
                participantList: [],
                pageNumber: 1,
                show:false,
                isOver:true,
                isSucces:true,
                isOpen:false
              })
              // console.log('微信支付', that.data.participantList)
              // wx.switchTab({
              //   url: '/pages/index/index'
              // })
              // that.goToRegisterPage();
              // if (that.data.item.isCheck == 1) {
              //   wx.showToast({
              //     title: "报名已提交审核",
              //     duration: 2000
              //   })
              // } else {
              //   wx.showToast({
              //     title: "恭喜您报名成功",
              //     duration: 2000
              //   })
              // }
              that.loadData()
              that.listActParticipantByAct()
              that.participantList(1)
            },
            fail(res) {
              that.setData({
                isOver: true,
              })
              console.log("支付已取消")
              console.log(res.errMsg)
            }
          })
        } else {
          that.setData({
            isOver: true,
            isOpen: false,
          })
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
            duration: 2000
          })
        }
      }
    });
    }
  },

  //获取钱包余额
  getWalletBalance: function () {
    let that = this
    let data = {
      "pageNumber": 1,
      "pageSize": 10
    }
    app.req({
      url: "wechat/account/expenseCalendars",
      method: "post",
      data: data,
      success: function (res) {
        if (200 == res.code) {
          that.setData({
            walletBalance: res.data.balance
          });
        } else {
          wx.showToast({
            title: res.msg,
            icon: 'none',
            duration: 2000
          })
        }
      }
    })
  },
  //预支付
  operationRecord() {
    let that = this
    var payPwd = CryptoJS.EncryptBASE64(timestamp + '|' + that.data.pwdVal)
    var amount = CryptoJS.EncryptBASE64(timestamp + '|' + that.data.paymentAmount)
    console.log('预支付参数', payPwd, amount)
    app.req({
      url: "wechat/wxpay/operationRecord",
      method: "post",
      data: {
        payPwd: payPwd,
        amount: amount
      },
      success: function (res) {
        if (200 == res.code) {
          that.setData({
            prepaymentRecordId: res.msg,
            pwdVal: ''
          });
          console.log('预支付', that.data.prepaymentRecordId)
          that.addToActivity(0)
        } else {
          that.setData({
            pwdVal: ''
          });
          wx.showToast({
            title: res.msg,
            icon: 'none',
            duration: 2000
          })
        }
      }
    })
  },
  // 支付密码
  /**
   * 隐藏支付密码输入层
   */
  hidePayLayer: function () {
    this.setData({
      pwdVal:'',
      showPayPwdInput: false,
      payFocus: false
    })

  },
  /**
   * 获取焦点
   */
  getFocus: function () {
    this.setData({ payFocus: true });
  },
  /**
   * 输入密码监听
   */
  inputPwd: function (e) {
    this.setData({ pwdVal: e.detail.value });
    if (this.data.pwdVal.length >= 6) {
      this.setData({
        showPayPwdInput: false,
        payFocus: false
      });
      this.operationRecord()
    }
  },

  //不参加
  noParticipation() {
    console.log("点击了不参加")
    var that = this;
    wx.showModal({
      content: '你确定拒绝加此活动么',
      cancelText: "再想想",
      confirmText: "确定",
      confirmColor: '#333333',
      cancelColor: '#3680FE',
      success(res) {
      if (res.confirm) {
      console.log("点击了不参加确定")
      app.req({
        url: "wechat/act/participation/refuse",
        method: "post",
        data: {
          activityId: that.data.id
        },
        success: function (res) {
          if (200 == res.code) {
            setTimeout(function () {
              wx.switchTab({
                url: '/pages/index/index'
              })
            }, 1000)
            console.log("if---", res.msg)
            wx.showToast({
              title: '已拒绝参加此活动',
              icon:'none',
              duration: 2000
            })
          } else {
            console.log("else---",res.msg)
            wx.showToast({
              title: res.msg,
              // icon:'none',
              duration: 2000
            })
          }
        }
      });
    }
   }
  })
  },
  //是否有报名权限
  checkAuth(){
    var that = this
    app.req({
      url: "wechat/act/participation/checkAuth",
      method: "post",
      data: {
        activityId: that.data.id
      },
      success: function (res) {
        if (200 == res.code) {
          if (res.data) {
           that.setData({
             ischeckAuth:true,
             ischeckAuth1:false
           })
          } else {
            console.log('11111',that.data.island)
            if (!that.data.island) {
              that.landbtn()
            } else {
            wx.showModal({
              content: '您暂无报名权限',
              confirmText: '返回上一页',
              showCancel:false,
              confirmColor: '#2168EB',
              success(res) {
                if (res.confirm) {
                  wx.switchTab({
                    url: '/pages/index/index'
                  })
                }
              }
            })
            }
            that.setData({
              ischeckAuth: false,
              ischeckAuth1: false
            })
          }

        }else if(res.code==501){
          that.setData({
            ischeckAuth1: true
          })
        } else {
          wx.showToast({
            title: res.msg,
            icon: 'none',
            duration: 2000
          })
        }
      }
    });
  },
  //报名参加活动
  signUp: function (e) {
    var that = this;
    if (!that.data.island) {
      that.landbtn()
    } else {
    that.loadData()
    var dateBegin = new Date(); //获取当前时间
    var dateEnd = new Date(that.data.item.applyEndTime.replace(/-/g, "/")); //将-转化为/，使用new Date
    var dateDiff = dateEnd.getTime() - dateBegin.getTime(); //时间差的毫秒数
    var applyEndTime = util.itemDateToShow(that.data.item.applyEndTime,1,true,false)
    if (dateDiff <= 0) {
      wx.showToast({
        title: "报名截止时间为" + applyEndTime+"晚了此时间无法报名",
        icon:'none',
        duration: 2000
      })
      return
    }
    if (that.data.item.perUpperLimit == that.data.item.number){
      wx.showToast({
        title: "本次活动已满，请联系活动发起人",
        icon: 'none',
        duration: 2000
      })
      return
    }
    if (that.data.item.actClass == 2 && !that.data.ischeckAuth){
      wx.showToast({
        title: "暂无报名权限",
        icon: 'none',
        duration: 2000
      })
      return
    }
      if (that.data.item.actClass == 2 && that.data.ischeckAuth1) {
        wx.showModal({
          title: '提示',
          content: '您需加入组织，才可报名活动',
          confirmText:'查看组织',
          confirmColor:'#2168EB',
          success(res) {
            if (res.confirm) {
              wx.navigateToMiniProgram({
                appId: app.globalData.activityMiniAppId,
                envVersion: app.globalData.activityMiniEnvVersion,
                path: 'pages/orgHome/orgHome?id=' + that.data.item.orgId,
                success(res) {
                  console.log(res);
                }
              })
            } else if (res.cancel) {
              return
            }
          }
        })
      }else{
    that.setData({
      formId : e.detail.formId
    })
    console.log("formid", that.data.formId)
    console.log("that.data.isPopup", that.data.isPopup)
    if (that.data.isPopup) {
      // that.setData({
      //   isOpen: true
      // })
      wx.navigateTo({
        url: '/pages/enrolldata/enrolldata?id=' + that.data.id + '&fullName=' + that.data.fullName + '&phoneNumber=' + that.data.phoneNumber + '&companyName=' + that.data.companyName + '&addNumber=' + that.data.addNumber + '&joinNumber=' + that.data.joinNumber + '&idNumber=' + that.data.idNumber + '&mailbox=' + that.data.mailbox + '&address=' + that.data.address + '&sex=' + that.data.sex + '&customArray=' + that.data.customArray + '&perUpperLimit=' + that.data.item.perUpperLimit + '&number=' + that.data.item.number,
      })
    } else {
      that.timeConflicts()
    }
    app.TestBuriedPoint('yqlw_invitedperson_enroll')
    }
    }
  },
  onClose: function () {
    this.setData({
      show: false
    });
  },


  //回到首页
  goHome: function () {
    wx.switchTab({
      url: '/pages/index/index'
    })
  },

//签到
  signIn(){
    app.TestBuriedPoint('yqlw_enroll_signin')
    var that = this;
    wx.navigateTo({
      url: '/pages/signinList/signinList?id='+that.data.id
    }) 
  },

  //取消行程
  cancelTheTrip(){
    app.TestBuriedPoint('yqlw_enroll_cancel')
    var that = this;
    if (that.data.item.chooseConsume !=1 && that.data.item.chooseConsume !=7){
      wx.showModal({
        content: '是否取消行程',
        cancelText: "再想想",
        confirmText: "取消行程",
        confirmColor: '#333333',
        cancelColor: '#3680FE',
        success(res) {
          if (res.confirm) {
            app.req({
              url: "wechat/act/participation/exit",
              method: "post",
              data: {
                activityId: that.data.id
              },
              success: function (res) {
                if (200 == res.code) {
                  wx.switchTab({
                    url: '/pages/index/index'
                  })
                  wx.showToast({
                    title: "行程取消成功",
                    duration: 2000
                  })
                } else {
                  wx.showToast({
                    title: res.msg,
                    icon: 'none',
                    duration: 2000
                  })
                }
              }
            });
          }
        }
      })
    } else if (that.data.item.chooseConsume==1 || that.data.item.chooseConsume==7){
      wx.showModal({
        title:'需要活动发起人审核后才可取消行程并退款',
        content: '是否取消行程',
        cancelText: "再想想",
        confirmText: "取消行程",
        confirmColor: '#333333',
        cancelColor: '#3680FE',
        success(res) {
          if (res.confirm) {
            app.req({
              url: "wechat/act/participation/exitMessage",
              method: "post",
              data: {
                activityId: that.data.id
              },
              success: function (res) {
                if (200 == res.code) {
                  wx.showToast({
                    title: "已发送审核",
                    duration: 2000
                  })
                  that.loadData()
                } else {
                  wx.showToast({
                    title: res.msg,
                    icon: 'none',
                    duration: 2000
                  })
                }
              }
            });
          }
        }
      })
    }
  },

  //留言
  leavingmessage(){
    getApp().mtj.trackEvent('yqlw_act_comment');
    if (!this.data.island) {
      this.landbtn()
    } else {
    wx.navigateTo({
      url: '/pages/interactionnew/interactionnew?id=' + this.data.id
    })
    }
  },
  //评论详情
  toDetails(e){
    var id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/interactionadd/interactionadd?id=' + id
    })
  },
  toDetails1(e) {
    var id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/interactionadd/interactionadd?id=' + id + '&istrue=1'
    })
  },
  //评论切换按钮
  isComment(){
    this.setData({
      isComment:true
    })
  },
  isComment1() {
    this.setData({
      isComment: false
    })
  },
  //邀请好友页面
  isshare(){
    this.setData({
      isshare:true
    })
    let logo = '';
    let headIcon = '';
    let code = '';
    this.getHead().then(headUrl => {
      console.log(headUrl);
      headIcon = headUrl
      return this.getLogo();
    }).then(logoUrl => {
      logo = logoUrl;
      return this.getCode();
    }).then(codeUrl => {
      code = codeUrl;
      return this.getcreateUrl();
      // this.drawImg(logo, headIcon, code);
      }).then(createUrl =>{
        createUrl = createUrl;
        this.drawImg(logo, headIcon, code, createUrl);
    })
  },
  //获取头像
  getHead() {
    return new Promise((resolve, reject) => {
      if (this.data.item.actClass != 2){
        wx.downloadFile({
          url: this.data._selData.headIcon,
          success: res => {
            resolve(res.tempFilePath)
          }
        })
      } else if (this.data.item.actClass == 2){
        wx.downloadFile({
          url: this.data._selData.headIcon1,
          success: res => {
            resolve(res.tempFilePath)
          }
        })
      }
    })
  },
//获取发起人
  getcreateUrl() {
    return new Promise((resolve, reject) => {
      wx.downloadFile({
        url: this.data._selData.headIcon,
        success: res => {
          resolve(res.tempFilePath);
        },
        fail: (err) => {
          console.log(er)
        }
      })
    })
  },

  //获取logo
  getLogo() {
    return new Promise((resolve, reject) => {
      wx.downloadFile({
        url: this.data._selData.logoUrl,
        success: res => {
          resolve(res.tempFilePath);
        },
        fail: (err) => {
          console.log(er)
        }
      })
    })
  },

  //获取二维码
  getCode() {
    return new Promise((resolve, reject) => {
      let tid = this.data._selData.tid;

      wx.downloadFile({
        url: this.data._selData.codeLogo,
        success: res => {
          resolve(res.tempFilePath);
        },
        fail: (err) => {
          console.log(er)
        }
      })
    })
  },
  drawText: function (ctx, str, leftWidth, initHeight, titleHeight, canvasWidth) {
    var lineWidth = 0;
    var lastSubStrIndex = 0; //每次开始截取的字符串的索引
    for (let i = 0; i < str.length; i++) {
      lineWidth += ctx.measureText(str[i]).width;
      if (lineWidth > canvasWidth) {
        ctx.fillText(str.substring(lastSubStrIndex, i), leftWidth, initHeight); //绘制截取部分
        initHeight +=30; //16为字体的高度
        lineWidth = 0;
        lastSubStrIndex = i;
        titleHeight += 30;
      }
      if (i == str.length - 1) { //绘制剩余部分
        ctx.fillText(str.substring(lastSubStrIndex, i + 1), leftWidth, initHeight);
      }
    }
    // 标题border-bottom 线距顶部距离
    titleHeight = titleHeight + 10;
    return titleHeight
  },
  //绘图
  drawImg(logo, headIcon, code,createUrl) {
    console.log(logo)
    console.log(headIcon)
    console.log(code)
    let bg = this.data.item.actType == 8 ? '../../img/img0701/share2.png' : (this.data.item.actType == 4 ? '../../img/img0701/share3.png' : (this.data.item.actType == 3 ? '../../img/img0701/share4.png':""))
    let title = this.data.item.topic;//帖子标题
    let authorName = ''; //用户昵称
    let tiem = this.data.item.createTime
    let map = this.data.item.actAddress == '' ? "待定" : this.data.item.actAddress

    let w = 0;
    if (this.data.item.actClass != 2){
      authorName = this.data.item.createName
    } else if (this.data.item.actClass == 2){
      authorName = this.data.item.orgName
    }
    wx.getSystemInfo({
      success: function (res) {
        w = res.screenWidth;
      },
    })

    let ctx = wx.createCanvasContext('shareFrends');

    ctx.fillStyle = '#ffffff';
    ctx.fillRect(0, 0, w / 750 * 670 * 2, w / 750 * 800 * 2);

    // if (title.length > 17) {
    //   title = title.slice(0, 17) + '...';
    // }

    //绘制logo
    // ctx.drawImage('../../public/images/1.jpg', 0, 0, w/750*670*2, w/750*380*2)
    ctx.drawImage(bg, 0, 0, w / 750 * 670 * 2, w / 750 * 600 * 2, 0, 0)
    ctx.drawImage(logo, w / 750 * 20 * 2, w / 750 * 20 * 2 , w / 750 * 630 * 2, w / 750 * 300 * 2, 0, 0)

    //绘制标题
    ctx.setFillStyle("#FFFFFF");
    ctx.fillRect(w / 750 * 20 * 2, w / 750 * 320 * 2 , w / 750 * 630 * 2, w / 750 * 250 * 2, 0, 0)
    ctx.setFontSize(w / 750 * 30 * 2)
    ctx.setFillStyle('#333333')//文字颜色
    // ctx.fillText(title, w / 750 * 32 * 2, w / 750 * 360 * 2)
    this.drawText(ctx, title, w / 750 * 32 * 2, w / 750 * 355 * 2, 148, w / 750 * 590 * 2)

    //绘制头像、昵称
    ctx.save()//保存当前的绘图上下文。
    ctx.beginPath()//开始创建一个路径
    //画一个圆形裁剪区域
    ctx.arc(w / 750 * 57 * 2, w / 750 * 421 * 2, w / 750 * 25 * 2, 0, 2 * Math.PI, false)
    ctx.clip()//裁剪

    //绘制图片
    ctx.drawImage(headIcon, w / 750 * 32 * 2, w / 750 * 396 * 2, w / 750 * 50 * 2, w / 750 * 50 * 2)
    ctx.restore()//恢复之前保存的绘图上下文

    ctx.setFontSize(w / 750 * 30 * 2)
    ctx.setFillStyle('#333333');
    //绘制文本
    ctx.fillText(authorName, w / 750 * 85 * 2, w / 750 * 417 * 2)
    ctx.setFontSize(w / 750 * 26 * 2)
    ctx.setFillStyle('#999999');
    ctx.fillText(tiem + '发起了活动', w / 750 * 85 * 2, w / 750 * 444 * 2)
    //绘制线条
    ctx.moveTo(w / 750 * 32 * 2, w / 750 * 460 * 2);
    ctx.lineTo(w / 750 * 638 * 2, w / 750 * 460 * 2);
    ctx.setLineWidth = 1;
    ctx.setStrokeStyle('#eeeeee')
    ctx.stroke();
    //内容
    ctx.drawImage('../../img/img0701/time.png', w / 750 * 32 * 2, w / 750 * 480 * 2, w / 750 * 20 * 2, w / 750 * 20 * 2)
    ctx.restore()//恢复之前保存的绘图上下文
    ctx.setFontSize(w / 750 * 26 * 2)
    ctx.setFillStyle('#333333');
    ctx.fillText('时间 ' + this.data.item.timeStr, w / 750 * 62 * 2, w / 750 * 500 * 2)

    ctx.drawImage('../../img/img0701/map.png', w / 750 * 32 * 2, w / 750 * 522 * 2, w / 750 * 20 * 2, w / 750 * 20 * 2)
    ctx.restore()//恢复之前保存的绘图上下文
    ctx.setFontSize(w / 750 * 26 * 2)
    ctx.setFillStyle('#333333');
    ctx.fillText('地点 ' + map, w / 750 * 62 * 2, w / 750 * 540 * 2)

    //绘制左下文案
    ctx.save()//保存当前的绘图上下文。
    ctx.beginPath()//开始创建一个路径
    ctx.arc(w / 750 * 63 * 2, w / 750 * 675 * 2, w / 750 * 30 * 2, 0, 2 * Math.PI, false)
    ctx.clip()//裁剪

    //绘制图片
    ctx.drawImage(createUrl, w / 750 * 32 * 2, w / 750 * 645* 2, w / 750 * 60 * 2, w / 750 * 60 * 2)
    ctx.restore()//恢复之前保存的绘图上下文
    ctx.setFontSize(w / 750 * 26 * 2)
    ctx.setFillStyle('#333333');
    //绘制文本
    ctx.fillText(authorName, w / 750 * 105 * 2, w / 750 * 670 * 2)
    ctx.setFontSize(w / 750 * 28 * 2)
    ctx.setFillStyle('#333333');
    ctx.fillText('邀请你参加活动', w / 750 * 105 * 2, w / 750 * 698 * 2)

    //绘制二维码
    ctx.drawImage(code, w / 750 * 518 * 2, w / 750 * 625 * 2, w / 750 * 100 * 2, w / 750 * 100 * 2);
    //绘制线条
    ctx.moveTo(w / 750 * 32 * 2, w / 750 * 750 * 2);
    ctx.lineTo(w / 750 * 638 * 2, w / 750 * 750 * 2);
    ctx.setLineWidth = 1;
    ctx.setStrokeStyle('#eeeeee')
    ctx.stroke();
    ctx.setFontSize(w / 750 * 18 * 2)
    ctx.setFillStyle('#aaaaaa');
    //绘制文本
    ctx.fillText('长', w / 750 * 32 * 2, w / 750 * 780 * 2)
    ctx.fillText('按', w / 750 * 82 * 2, w / 750 * 780 * 2)
    ctx.fillText('二', w / 750 * 142 * 2, w / 750 * 780 * 2)
    ctx.fillText('维', w / 750 * 222 * 2, w / 750 * 780 * 2)
    ctx.fillText('码', w / 750 * 302 * 2, w / 750 * 780 * 2)
    ctx.fillText('立', w / 750 * 382 * 2, w / 750 * 780 * 2)
    ctx.fillText('即', w / 750 * 462 * 2, w / 750 * 780 * 2)
    ctx.fillText('参', w / 750 * 542 * 2, w / 750 * 780 * 2)
    ctx.fillText('与', w / 750 * 622 * 2, w / 750 * 780 * 2)

    ctx.draw(false, () => {
      //调用接口将画布转换为图片
      wx.canvasToTempFilePath({
        x: 0,
        y: 0,
        fileType: 'jpg',
        quality: 1,
        width: w / 750 * 670 * 2,
        height: w / 750 * 800 * 2,
        destWidth: w / 750 * 670 * 2,
        destHeight: w / 750 * 800 * 2,
        canvasId: 'shareFrends',
        success: res => {

          wx.hideToast();

          this.setData({
            sharePicUrl: res.tempFilePath   //生成的图片路径
          }, () => {

            //渲染完后再显示分享海报
            this.setData({
              share: false,
              showSharePic: true
            })

          })
          console.log('图片路径', this.data.sharePicUrl)
        },
        fail(err) {
          wx.showToast({
            title: '图片生成失败，请稍候再试！',
            icon: 'none',
            mask: true
          })
        }
      })
    }
    );

  },
  //保存图片
  savePic() {
    let sharePicUrl = this.data.sharePicUrl;
    console.log('保存1111', sharePicUrl)
    getApp().mtj.trackEvent('yqlw_act_save_img');
    wx.getSetting({
      success: res => {
        if (res.authSetting['scope.writePhotosAlbum'] == false) {
          wx.showModal({
            title: '提示',
            content: '是否授权将相册保存到相册？',
            confirmColor: '#2ca2ed',
            success: res => {
              //点击确定打开授权设置
              if (res.confirm) {

                wx.openSetting({
                  success: res => {

                    setTimeout(() => {
                      if (res.authSetting['scope.writePhotosAlbum'] == true) {

                        wx.saveImageToPhotosAlbum({
                          filePath: sharePicUrl,
                          success: res => {
                            wx.showToast({
                              title: '保存成功！',
                              icon: 'success',
                              mask: true
                            })
                          },
                          fail: err => {
                            wx.showToast({
                              title: '图片生成中，请稍后再试',
                              icon: 'none',
                              mask: true
                            })
                          }
                        })

                      } else {
                        wx.showToast({
                          title: '图片生成中，请稍后再试',
                          icon: 'none',
                          mask: true
                        })
                      }
                    }, 500)

                  }
                })

              }

            }
          })
        } else {
          console.log('保存22222',sharePicUrl)
          wx.saveImageToPhotosAlbum({
            filePath: sharePicUrl,
            success: res => {
              wx.showToast({
                title: '保存成功！',
                icon: 'success',
                mask: true
              })
            },
            fail: err => {
              console.log('保存22222', err)
              wx.showToast({
                title: '授权失败',
                icon: 'none',
                mask: true
              })
            }
          })

        }
      }
    })

  },

  preventTouchMove: function (e) {
  },
  //阅读全部
  wholeopen(){
    this.setData({
      wholeopen: !this.data.wholeopen,
    })
  },

  showSheet: function() {
    console.log('重开', this.data.applyEnd,this.data.item.status);
    if (this.data.mine) {
      this.toggle("showSheet", true);
    }
  },



  onCloseSheet: function() {
    this.toggle("showSheet", false);
  },



  toTransportPage: function() {
    var that = this;
    wx.navigateTo({
      url: '/pages/transportstatistics/transportstatistics?id=' + that.data.id
    })
  },


  toRemarksPage: function() {
    var that = this;
    wx.navigateTo({
      url: '/pages/partremarks/partremarks?id=' + that.data.id
    })
  },


  toDetailPage(){
    wx.navigateTo({
      url: '/pages/registerDetail/registerDetail?id=' + this.data.id
    })
  },


  stringToDate: function(d1) {
    var that = this;
    if (that.data.item.status == 4) {
      return "活动报名已结束";
    }
    //如果时间格式是正确的，那下面这一步转化时间格式就可以不用了
    var dateBegin = new Date(); //获取当前时间
    var dateEnd = new Date(d1.replace(/-/g, "/")); //将-转化为/，使用new Date
    var dateDiff = dateEnd.getTime() - dateBegin.getTime(); //时间差的毫秒数
    console.log('报名截止3', dateDiff)
    if (dateDiff <= 0) {
      if (that.data.isShuax) {
        that.loadData()
      }
      that.setData({
        applyEnd: true,
        registeEnd: true,
        isShuax: false
      })
      console.log('报名截止', that.data.registeEnd)
      return "活动报名已经结束";
    }
    var dayDiff = Math.floor(dateDiff / (24 * 3600 * 1000)); //计算出相差天数
    var leave1 = dateDiff % (24 * 3600 * 1000) //计算天数后剩余的毫秒数
    var hours = Math.floor(leave1 / (3600 * 1000)) //计算出小时数
    //计算相差分钟数
    var leave2 = leave1 % (3600 * 1000) //计算小时数后剩余的毫秒数
    var minutes = Math.floor(leave2 / (60 * 1000)) //计算相差分钟数
    //计算相差秒数
    var leave3 = leave2 % (60 * 1000) //计算分钟数后剩余的毫秒数
    var seconds = Math.round(leave3 / 1000)
    var text = "报名剩余时间";
    if ((dayDiff * 24 + hours) > 0) {
      text += (dayDiff * 24 + hours) + "小时";
    }
    if (minutes > 0) {
      text += (minutes < 10 ? "0" + minutes : minutes) + "分钟";
    }
    text += (seconds < 10 ? "0" + seconds : seconds) + "秒";
    return text;
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    // wx.hideShareMenu()
    // wx.showShareMenu({
    //   withShareTicket: true
    // })
    // console.log('活动id', JSON.stringify(options))
    console.log("options----", options)
    var that = this
    that.setData({
      id: options.id || options.scene,
      source: options.source || '',
    })
    // that.participantList()
    that.toggle("mediaObject.activityID", that.data.id);
    if (options.isShare) {
      this.setData({
        isShare: options.isShare
      })
    }
    if (this.data.isShare == 1) {
      console.log("isShare====2")
      wx.setStorageSync('loginActId', options.id)
    }
    if (options.source == 'iOSAPP' || options.source == 'AndroidAPP'){
      wx.setStorageSync('loginActId', options.id)
      // console.log('app进入活动id')
    }
    // console.log("app进来的", options.id, options.source)
    if (wx.getStorageSync('dirty') == undefined || wx.getStorageSync('dirty') == '') {
      this.getdirty()
    } else {
      this.setData({
        dirty: wx.getStorageSync('dirty')
      });
    }
      
  },




  loadDict: function() {
    var that = this;
    app.req({
      url: "wechat/dictionary/listBydictType",
      method: "post",
      data: {
        dictType: "ACT_TRANSPORT"
      },
      success: function(res) {
        if (200 == res.code) {
          var list = res.data;
          var dict = {};
          for (var i in list) {
            var item = list[i];
            dict[item.dictValue] = item.dictName
          }
        } else {
          wx.showToast({
            title: res.msg,
            icon: 'none',
            duration: 2000
          })
        }
        that.toggle("dict", dict);
      }
    });
  },


  showGPS: function() {
    var that = this;
    var data = that.data.item;
    const latitude = data.latitude * 1;
    const longitude = data.longitude * 1;
    const name = data.actAddress;
    const address = data.actAddress;
    var data = {
      latitude,
      longitude,
      scale: 18,
      name,
      address
    };
    var that = this;
    wx.openLocation(data);
  },


  
  loadList: function() {
    var that = this;
    app.req({
      url: "wechat/act/participation/listAllActParticipant",
      method: "post",
      data: {
        activityId: that.data.id
      },
      success: function(res) {
        if (200 == res.code && res.data) {
          console.log("报名信息",res)
          var itemList = res.data;
          var userId = that.data.userInfo.id;
          for (var i = 0; i < itemList.length; i++) {
            var itemVar = itemList[i];
            if (itemVar.participantId == userId) {
              that.toggle("registeOver", true);
              that.toggle("isCheck", itemVar.isCheck);
            }
            if (itemVar.participantId == userId) {
              that.toggle("mine", true);
              // that.toggle("enrolment", true);
              // console.log("enrolment", that.data.enrolment)
            } 
            
            if (itemVar.participantId == userId) {
              that.toggle("myTransport", itemVar.transportation * 1);
              that.toggle("myTips", itemVar.remark);
            }
          }
        } else {
          console.log("报错")
          console.log(res.msg)
          wx.showToast({
            title: res.msg,
            icon: 'none',
            duration: 2000
          })
        }
      }
    });
  },
  
  loadData: function() {
    var that = this;
    app.req({
      url: "wechat/activity/activityDetail",
      method: "post",
      data: {
        id: that.data.id
      },
      success: function(res) {
        if (200 == res.code) {
          console.log("活动详情",res)
          if (res.data.actClass==2){
            if (res.data.isRecommend==0){
              if (res.data.actStatus==0){
                that.setData({
                  isexamineorg:true
                })
              } else if (res.data.actStatus == 2){
                that.setData({
                  isexamineorg1: true
                })
              }
            } else if (res.data.isRecommend == 1){
              if (res.data.actStatus == 0) {
                that.setData({
                  isexamineorg: true
                })
              } else if (res.data.actStatus == 1 || res.data.actStatus == -1){
                if (res.data.recommendStatus==0){
                  that.setData({
                    isexaminept: true
                  })
                } else if (res.data.recommendStatus == 2){
                  that.setData({
                    isexaminept1: true
                  })
                }
              }else if (res.data.actStatus == 2) {
                that.setData({
                  isexamineorg1: true
                })
              }
            }
          }
          var dateBegin = new Date(); //获取当前时间
          var dateEnd = new Date(res.data.applyEndTime.replace(/-/g, "/")); //将-转化为/，使用new Date
          var dateDiff = dateEnd.getTime() - dateBegin.getTime(); //时间差的毫秒数
          console.log('报名截止3', dateDiff)
          if (dateDiff <= 0) {
            that.setData({
              applyEnd: true
            })
          }
          if (res.data.actEndTime != res.data.applyEndTime){
            that.setData({
              isapplyEndTime:true
            })
          }
          var actEndTime = util2.itemDateToShow(res.data.actEndTime, 1, true, false)
          var actStartTime = util2.itemDateToShow(res.data.actStartTime, 1, true, false)
            res.data.actStartTime = util2.itemDateToShow(res.data.actStartTime, 1, false, false)
          res.data.createTime = util2.itemDateToShow(res.data.createTime, 1, false, false).substring(5, 11)
          res.data.applyEndTime = util.itemDateToShow(res.data.applyEndTime, 1, true, false)
          res.data.actEndTime = util.formatTime4(res.data.actEndTime).replace("-", ".").replace("-", ".")
          that.toggle("item", res.data);
          WxParse.wxParse('activityProcess', 'html', that.data.item.activityProcess, that, 5);
          that.toggle("_selData.logoUrl", res.data.actPoster);
          that.toggle("_selData.headIcon", res.data.createUrl);
          that.toggle("_selData.headIcon1", res.data.orgUrl);
          that.toggle("_selData.codeLogo", res.data.orUrl);
          that.setData({
            extras: res.data.extras,
            groupNotice: res.data.groupNotice,
            signIn: res.data.signIn,
            actEndTime: actEndTime,
            actStartTime: actStartTime, 
          })
          if (res.data.joinType==1){
            that.toggle('enrolment',true)
          }else{
            that.toggle('enrolment', false)
          }
          var exarr=[]
          for (var i = 0; i < res.data.extras.length; i++) {
            if (res.data.extras[i].isChoose == 1) {
              exarr.push(res.data.extras[i])
            }
          }
          if (res.data.isName == 1 || res.data.isTelphone == 1 || res.data.isEnrollment == 1 || res.data.isCompany == 1 || res.data.isIdcard == 1 || res.data.isEmail == 1 || res.data.isAddress == 1 || exarr.length > 0) {
            that.setData({
              isPopup:true
            })
          }

          var arr = []
          var item = ""
          for (let i = 0; i < that.data.extras.length ;i++) {
            arr.push(item)
            that.setData({
              inputVal: arr
            })
          }
          console.log("inputVal--", that.data.inputVal)
        
          var uid = that.data.userInfo.id;
          if (that.data.item.createUid != uid){
            console.log('仅查看')
            that.browse()
          }
          if (that.data.item.createUid == uid) {
            console.log('发起人',)
            that.setData({
              isCreate:true
            })
          } else {
            that.setData({
              isCreate: false
            })
          }
          var actType = res.data.actType
          // console.log('导航栏', actType)
          if (actType==1){
            wx.setNavigationBarTitle({
              title: '团购'
            })
          } else if (actType ==2){
            wx.setNavigationBarTitle({
              title: '打游戏'
            })
          }else if(actType==3){
            wx.setNavigationBarTitle({
              title: '运动'
            })
          }
          else if (actType == 4) {
            wx.setNavigationBarTitle({
              title: '宴请'
            })
          } else if (actType == 5) {
            wx.setNavigationBarTitle({
              title: '团建'
            })
          } else if (actType == 6) {
            wx.setNavigationBarTitle({
              title: '婚礼'
            })
          } else if (actType == 7) {
            wx.setNavigationBarTitle({
              title: '大型活动'
            })
          } else if (actType == 8) {
            wx.setNavigationBarTitle({
              title: '会议'
            })
          } else if (actType == 9) {
            wx.setNavigationBarTitle({
              title: '商家活动'
            })
          } else if (actType == 10) {
            wx.setNavigationBarTitle({
              title: '活动详情'
            })
          } else if (actType ==11) {
            wx.setNavigationBarTitle({
              title: '公益'
            })
          }
          // that.showTime();
          //获取内容高度
          // if (that.data.item.activityProcess) {
          //   var query = wx.createSelectorQuery();
          //   //选择id
          //   query.select('#mjltest').boundingClientRect()
          //   query.exec(function (res) {
          //     //res就是 所有标签为mjltest的元素的信息 的数组
          //     console.log('高度信息', res);
          //     //取高度
          //     // console.log('高度', res[0].height);
          //     if (res[0].height > 40) {
          //       that.setData({
          //         nrheight: 80
          //       })
          //     }
          //   })
          // }
        } else {
          wx.showToast({
            title: res.msg,
            icon: 'none',
            duration: 2000
          })
        }
      }
    });
  },


  //活动参与人列表
  listActParticipantByAct(){
    var that = this;
    // console.log("活动id", that.data.id)
    app.req({
      url: "wechat/act/participation/listActParticipantByActId",
      method: "post",
      data: {
        activityId: that.data.id,
        isCheck:1
      },
      success: function (res) {
        if (200 == res.code) {
          var itemList = res.data;
          //  console.log("新街口", res)
          var userId = that.data.userInfo.id;
          for (var i = 0; i < itemList.length; i++) {
            var itemVar = itemList[i];
            if (itemVar.participantId == userId) {
              that.toggle("isCheck", itemVar.isCheck);
              // that.toggle("enrolment", true);
            }
          }
        } else {
          wx.showToast({
            title: res.msg,
            icon: 'none',
            duration: 2000
          })
        }
      }
    });
    
  },

//隐藏报名成功弹框
  clearX(){
    this.setData({
      isSucces:false
    })
  },
  //报名人员跳转
  sigupmore(){
    if(this.data.isexport){
      this.setData({
        isexport: false,
      })
      wx.navigateTo({
        url: '/pages/enlistManage/enlistManage?id=' + this.data.id + '&isEnrollment=' + this.data.item.isEnrollment
      })
    }
  },
  //活动审核
  sigupmore2() {
    if(this.data.isexport){
      this.setData({
        isexport: false,
      })
      wx.navigateTo({
        url: '/pages/enlistManage2/enlistManage2?id=' + this.data.id
      })
    }
  },
  //费用管理
  costbtn(){
    if(this.data.isexport){
      this.setData({
        isexport: false,
      })
    wx.navigateTo({
      url: '/pages/costmanagement/costmanagement?id=' + this.data.id,
    })
    }
    },

  //导出列表
  exportList: function () {
    var that = this;
    if(that.data.isexport){
      that.setData({
        isexport:false,
      })
    app.req({
      url:'wechat/activity/newExportParticipation',
      method: "post",
      data: {
        activityId: that.data.id
      },
      success: function (res) {
        if (200 == res.code) {
          that.setData({
            fileName: res.data.fileName,
            fileSize: res.data.fileSize,
          })
          console.log('导出', res, that.data.fileName)
          wx.navigateTo({
            url: '/pages/exportList/exportList?fileName=' + that.data.fileName + '&id=' + that.data.id + '&fileSize=' + that.data.fileSize,
          })
        } else {
          that.setData({
            isexport: true,
          })
          wx.showToast({
            title: res.msg,
            icon: 'none',
            duration: 2000
          })
        }
      }
    })
  }
  },
  //管理相册  报名成功后，活动结束前
  albumimg() {
    app.TestBuriedPoint('yqlw_enroll_album')
    wx.navigateTo({
      url: '/pages/album/album?id=' + this.data.id + '&status=0' + '&originatorID=' + this.data.item.createUid
    })
  },
  //管理相册  活动结束后
  albumimgEnd() {
    app.TestBuriedPoint('yqlw_end_see')
    wx.navigateTo({
      url: '/pages/album/album?id=' + this.data.id + '&status=1' + '&originatorID=' + this.data.item.createUid
    })
  },


  showTime: function() {
    var that = this;
    console.log('报名截止1', that.data.applyEnd)
    if (!that.data.applyEnd) {
      console.log('报名截止2', that.data.item.applyEndTime)
      setInterval(function() {
        that.setData({
          time: that.stringToDate(that.data.item.applyEndTime)
        })
      }, 1000);
    }
  },
  toggle: function(type, val) {
    this.setData({
      [type]: val
    });
  },
  bindErrorImg: function() {
    this.toggle("item.actPoster", "/img/temp.png")
  },
  toUserIndex: function(event) {
    var data = event.currentTarget.dataset;
    console.log(data.id)
    wx.navigateTo({
      url: '/pages/myindex/myindex?id=' + data.id
    })
  },
  toUserList: function() {
    var that = this;
    wx.navigateTo({
      url: '/pages/listmanage/listmanage?id=' + that.data.id
    })
  },
  toActivityWallet: function() {
    var that = this;
    wx.navigateTo({
      url: '/pages/mywallet/mywallet?activityId=' + that.data.id
    })
  },
  toActivityChat: function() {
    var that = this;
    wx.navigateTo({
      // url: '/pages/interaction/interaction?activityId=' + that.data.id
      url: '/pages/interactionnew/interactionnew?activityId=' + that.data.id
    })
  },
  updateActivity: function() {
    app.TestBuriedPoint('yqlw_invitation_modify')
    //修改活动
    var that = this;
    if(that.data.item.actType==10){
      wx.showModal({
        title: '提示',
        content: '请到官网进行修改',
        confirmColor: '#2168EB',
        showCancel: false,
        success(res) {
          if (res.confirm) {
            console.log('用户点击确定')
          }
        }
      })
    }else{
    if (that.data.item.number>1){
      wx.navigateTo({
        url: '/pages/party/party?id=' + that.data.id + "&isModify=1" + "&isModify1=1"
      })
    }else{
      wx.navigateTo({
        url: '/pages/party/party?id=' + that.data.id + "&isModify1=1"
      })
    }
    }

  },
  cancleActivity: function() {
    app.TestBuriedPoint('yqlw_Invitation_cancel')
    app.TestBuriedPoint('yqlw_invitation_modify')
    //取消活动
    var that = this;
    that.toggle("showSheet", false);
    wx.showModal({
      content: '是否取消此活动？',
      cancelText:'再想想',
      cancelColor:'#629BF9',
      confirmText:'确定',
      confirmColor: "#333333",
      success(res) {
        if (res.confirm) {
          app.req({
            url: "wechat/activity/cancelActivity",
            method: "post",
            data: {
              id: that.data.id
            },
            success: function(res) {
              if (res.code == 200) {
                // wx.navigateBack({
                //   delta: 1
                // })
                setTimeout(function () {
                  wx.switchTab({
                    url: '/pages/index/index'
                  }) 
                }, 500)
                wx.showToast({
                  title: "活动取消成功",
                  duration: 2000
                })
              } else {
                wx.showToast({
                  title: res.msg,
                  icon: 'none',
                  duration: 2000
                })
              }
            }
          });
        }
      }
    })

  },
  createActivity: function() {
    app.TestBuriedPoint('yqlw_end_start')  //在此发起活动埋点
    var that = this;
    that.toggle("showSheet", false);
    wx.showModal({
      content: '确定要再发布一次活动吗?',
      confirmColor: "#629BF9",
      success(res) {
        if (res.confirm) {
          app.req({
            url: "wechat/activity/endApply",
            method: "post",
            data: {
              activityId: that.data.id,
              operate: 2
            },
            success: function(res) {

            }
          });
        }
      }
    })
    this.copyActivity();
  },
  //删除活动
  deletebtn(){
    app.TestBuriedPoint('yqlw_end_delete')
    var that = this
    wx.showModal({
      content: '删除此活动?',
      cancelText: "返回",
      confirmText: "删除",
      confirmColor: '#333333',
      cancelColor:'#3680FE',
      success(res) {
        if (res.confirm) {
          app.req({
            url: "wechat/activity/deleteByActId",
            method: "post",
            data: {
              id: that.data.id
            },
            success: function (res) {
              if (res.code == 200) {
                setTimeout(function () {
                  wx.switchTab({
                    url: '/pages/index/index'
                  })
                }, 500)
                wx.showToast({
                  title: '删除成功',
                  duration: 2000
                })
              } else {
                wx.showToast({
                  title: res.msg,
                  icon: 'none',
                  duration: 2000
                })
              }
            }
          });
        }
      }
    })
  },
  updateActivityMoney: function() {
    //多退少补
    var that = this;
    that.toggle("showSheet", false);
    wx.showModal({
      content: '确定向活动参与者退换(补收)多余(不足)的费用吗?',
      confirmColor: "#629BF9",
      success(res) {
        if (res.confirm) {

        } else if (res.cancel) {}
      }
    })
  },
  saveInviteCodeToLocal: function() {
    var that = this;
    wx.showModal({
      content: '确定跳转到邀请函页面吗?',
      confirmColor: "#629BF9",
      success(res) {
        if (res.confirm) {
          wx.navigateTo({
            url: '/pages/partyInvitation/partyInvitation?id=' + that.data.id
          })
        }
      }
    })
  },
  giveActivityMoney: function() {
    //活动补款
    var that = this;
    that.toggle("ShowGiveActivityMoney", true);
  },
  copyActivity: function() {
    app.TestBuriedPoint('yqlw_end_start')
    //复制模板发起活动
    var that = this;
    wx.showModal({
      content: '确定再次发起活动吗?',
      cancelText: "返回",
      confirmText: "确定",
      confirmColor:'#3680FE',
      cancelColor: '#333333',
      success(res) {
        if (res.confirm) {
          wx.navigateTo({
            url: '/pages/party/party?id=' + that.data.id + "&isCopy=1"
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
    // if (this.data.isHeight){
    //   this.roll()
    // }
  },
  //是否关注公众号
  concernWechat: function () {
    var that = this;
    app.req({
      url: "wechat/sys/register",
      method: "post",
      success: function (res) {
        // that.toggle("concern", !!res);
      }
    });
  },
  addOtherorg(){
    var that = this
    wx.navigateToMiniProgram({
      appId: app.globalData.activityMiniAppId,
      envVersion: app.globalData.activityMiniEnvVersion,
      path: 'pages/index/index',
      success(res) {
        console.log(res);
      }
    })
  },
  addorg() {
    var that = this
    wx.navigateToMiniProgram({
      appId: app.globalData.activityMiniAppId,
      envVersion: app.globalData.activityMiniEnvVersion,
      path: 'pages/orgHome/orgHome?id=' + that.data.item.orgId,
      success(res) {
        console.log(res);
      }
    })
  },

  //浏览活动
  browse() {
    var that = this
    app.req({
      url: 'wechat/browse/save',
      data: {
        actId:that.data.id
      },
      method: 'POST',
      success: function (res) {
        console.log("---bahahahha------", res);
        if (res.code == 200) {

        } else {
          wx.showToast({
            title: res.msg,
            icon: 'none',
            duration: 2000
          })
        }
      }
    })
  },
  //获取是否有密码
  getIspswd(){
    var that = this
    app.req({
      url: 'wechat/user/whetherSetPayPwd',
      data: {
      },
      method: 'POST',
      success: function (res) {
        console.log('密码',res);
        if (res.code == 200) {
          that.setData({
            whetherSetPayPwd: res.data.whetherSetPayPwd
          })
        }
      }
    })
  },
  getdirty() {
    var that = this
    app.req({
      url: "wechat/dirty/all",
      method: "post",
      success: function (res) {
        // console.log('脏字库')
        if (res.code == 200) {
          wx.setStorageSync('dirty', res.data);
          that.setData({
            dirty: res.data
          })
        }
      }
    });
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    app.TestBuriedPoint('yqlw_invitation_pv')
    var that = this;
    that.setData({
      isexamineorg: false,
      isexamineorg1: false,
      isexaminept: false,
      isexaminept1: false,
    })
    wx.getSetting({
      success: (res) => {
        console.log('授权', res)
        if (wx.getStorageSync('uid')) {
          console.log('已授权登陆')
          that.setData({
            island: true
          })
          //获取头像及名称
          app.getUserInfo(function (userInfo) {
            that.toggle("userInfo", userInfo);
            that.setData({
              user: userInfo,
              hiddenName: true,
              hiddenName1: true,
              hiddenName2: true
            })
            console.log("来拉我", userInfo)
            that.loadDict();
            that.listActParticipantByAct();
            that.concernWechat();
            that.loadData()
            that.checkAuth()
          })
        }else{
          that.setData({
            island: false
          })
        }
      }
    })
    that.setData({
      isexport:true,
      participantList: [],
      leaveInfo: [],
      pageNumber: 1,
      pageNumber1: 1,
    })
    that.getlists()
    that.getLeaveMessage()
    that.participantList(1)
    that.getChangeMessage()
    that.getIspswd()
    // that.checkAuth()
    that.loadData()
    if (that.data.isOpen) {
      that.timeConflicts()
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    let pages = getCurrentPages();
    let prevpage = pages[pages.length - 1];
    console.log("从哪个页面来的")
    console.log(pages)
    if (this.data.partyBack) {
      console.log('dfhiiidshidiidssiiiiiiiiiiiiiiiiiiiiiii')
      wx.reLaunch({
        url: '/pages/index/index'
      })
    }
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {
      var pages = getCurrentPages();
      if (pages.length >=2) {
        var currPage = pages[pages.length - 1];  //当前页面
        var prevPage = pages[pages.length - 2];
        console.log("register-pages长度", pages)
        console.log("register-prevPage页面", prevPage.route)
        prevPage.setData({
          partyBack: true
        })
      }
     
    // }
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    if (this.data.isComment){
      console.log('评论页数1', this.data.pageNumber1, this.data.leaveIntotalPages)
      if (this.data.leaveIntotalPages > this.data.pageNumber1){
        this.setData({
          pageNumber1: this.data.pageNumber1 + 1
        })
        console.log('评论页数', this.data.pageNumber1)
        this.getLeaveMessage()
      }
    }else{
      if (this.data.participantListpages > this.data.pageNumber){
        this.setData({
          pageNumber: this.data.pageNumber + 1
        })
        console.log('已报名页数', this.data.pageNumber)
        this.participantList()
      }
    }
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (e) {
    console.log(e)
    var that = this
    var id = e.target.dataset.id
    app.req({
      url: 'wechat/activity/share',
      data: {
        id:that.data.id,
        type:1,
      },
      method: 'POST',
      success: function (res) {
        console.log('分享数量', res);
      }
    })
    if (id == 1) {
      console.log('分享主题', that.data.item.topic)
      getApp().mtj.trackEvent('yqlw_act_share_wx');
      that.setData({
        hiddenName: false,
        isshare: false,
        callback: function () {
        }
      })
    } else if (id == 2) {
      getApp().mtj.trackEvent('yqlw_act_sigup_wx');
      console.log('分享主题', that.data.item.topic)
      that.setData({
        hiddenName1: false,
        callback: function () {
        }
      })
    } else if (id == 3) {
      getApp().mtj.trackEvent('yqlw_act_share_wx');
      console.log('分享主题', that.data.item.topic)
      that.setData({
        hiddenName2: false,
        callback: function () {
        }
      })
    }
    if (that.data.id == 'a839aaf9cfbf11e9864b00163e05ff66'){
      return {
        title: '活动：' + that.data.item.topic,
        path: '/pages/webviews/webviews?&id=' + that.data.id + '&isShare=1',
        success(e) {
          console.log("分享成功了")
        },
        fail(e) {
          console.log("分享失败")
        }
      }
    } else if (that.data.id == '0dc5b931bfef11e9864b00163e05ff66'){
      return {
        title: '活动：' + that.data.item.topic,
        path: '/pages/webview/webview?&id=' + that.data.id + '&isShare=1',
        success(e) {
          console.log("分享成功了")
        },
        fail(e) {
          console.log("分享失败")
        }
      }
    }else{
      return {
        title: '活动：' + that.data.item.topic,
        path: '/pages/register/register?&id=' + that.data.id + '&isShare=1',
        success(e) {
          console.log("分享成功了")
        },
        fail(e) {
          console.log("分享失败")
        }
      }
    }
  },
  shareButton: function(){
    app.TestBuriedPoint('yqlw_invitation_invitation')
  },
  //发起人头像跳转
  goHomePage(){
    var that = this
    console.log('createUid',that.data.item.createUid)
    console.log('userInfoid',that.data.userInfo.id)
    var viewUid = that.data.item.createUid
    var userId = that.data.userInfo.id
    if (viewUid == userId) {
      wx.navigateTo({
        url: '/pages/myinfo/myinfo'
      });
    } else {
      wx.navigateTo({
        url: '/pages/myinfo/myinfo?viewUid=' + viewUid
      });
    }
  },
  //跳转组织
  goOrg(){
    var that = this
    var orgid = that.data.item.orgId
    wx.navigateToMiniProgram({
      appId: app.globalData.activityMiniAppId,
      envVersion: app.globalData.activityMiniEnvVersion,
      path: 'pages/orgHome/orgHome?id=' + orgid,
      success(res) {
        console.log(res);
      }
    })
  },
  //留言跳转
  toHomePage:function(option){
    var that = this
    console.log(option.currentTarget.dataset.title)
    console.log(that.data.userInfo.id)
    var viewUid = option.currentTarget.dataset.title
    var userId = that.data.userInfo.id
    if (viewUid == userId){
      wx.navigateTo({
        url: '/pages/myinfo/myinfo'
      });
    }else{
      wx.navigateTo({
        url: '/pages/myinfo/myinfo?viewUid=' + viewUid
      });
    }
    
  },
  isLeaveOpen: function (option){
    var that = this
    console.log(option.currentTarget.dataset.name)
    var num = option.currentTarget.dataset.name
    var index = "leaveInfo[" + num + "].flag"
    that.setData({
      [index]: !that.data.leaveInfo[num].flag
    })
  },

  getChangeMessage:function(){
    var that = this
    var data = {
      'activityId':that.data.id
    }
    app.req({
      url: "wechat/sysMessage/changeMessage",
      method: "post",
      data: data,
      success: function (res) {
        if (200 == res.code) {
          if(res.data == ''){
            // console.log('没有变更',res)
          }else{
            // console.log('变更提示', res.data.content,res)
            that.setData({
              isMsg:true,
              changeMessageId:res.data.id,
              bgmsg: res.data.updateActInfoArr
            })
            console.log('没有变更', that.data.bgmsg)
          }
        } else {
          wx.showToast({
            title: res.msg,
            icon: 'none',
            duration: 2000
          })
        }
      }
    });
  },
  //变更消息查看
  msglook(){
    var newId = this.data.changeMessageId
    var data1 = {
      "ids": [newId]
    }
    app.req({
      url: "wechat/sysMessage/update",
      method: "post",
      data: data1,
      success: function (res3) {
        if (200 == res3.code) {
          wx.navigateTo({
            url: '/pages/mymessage/mymessage?id=' + newId
          });
        }
      }
    })
    this.setData({
      isMsg:false
    })
  },
  //变更确定
  msgxs(){
    var newId = this.data.changeMessageId
    var data1 = {
      "ids": [newId]
    }
    app.req({
      url: "wechat/sysMessage/update",
      method: "post",
      data: data1,
      success: function (res3) {
        if (200 == res3.code) {
        }
      }
    })
    this.setData({
      isMsg: false
    })
  },
  getPhoneNumber: function (e) {//点击获取手机号码按钮
    var that = this;
    wx.login({
      success: (res) => {
        console.log(res)
        var ency = e.detail.encryptedData;
        var iv = e.detail.iv;
        var sessionk = that.data.sessionKey;
        if (e.detail.errMsg == 'getPhoneNumber:fail user deny') {
          that.setData({
            modalstatus: true
          });
        } else {//同意授权
          app.req({
            method: "post",
            url: 'wechat/sysMessage/deciphering',
            data: {
              encrypdata: ency,
              ivdata: iv,
              code: res.code
            },
            header: {
              'content-type': 'application/json' // 默认值
            },
            success: (res) => {
              console.log("解密成功~~~~~~~将解密的号码保存到本地~~~~~~~~");
              console.log(res);
              var phone = res.data.telPhone;
              that.setData({ phoneNumber: phone })
            }, fail: function (res) {
              console.log("解密失败~~~~~~~~~~~~~");
              console.log(res);
            }
          });
        }
      }
    })
  },
  //app跳转
  launchAppError: function (e) {
    console.log('错误回调',e.detail.errMsg)
  } ,
  launchapp: function (e) {
    console.log('成功回调',e)
  },
  // 登录
  landbtn() {
    this.toggle('loginShow', true)
    this.selectComponent('#login').showClose()
  },
  toggleToast(e) {
    console.log(e.detail)
    if (!e.detail.loginShow){
      this.toggle('loginShow', false)
    }
    this.onShow()
  },

})